<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>A_A - 极简全栈示例</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #333;
        }

        .container {
            background: white;
            padding: 3rem;
            border-radius: 20px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            text-align: center;
            max-width: 400px;
            width: 90%;
        }

        h1 {
            color: #667eea;
            margin-bottom: 1rem;
            font-size: 2.5rem;
        }

        .subtitle {
            color: #666;
            margin-bottom: 2rem;
            font-size: 1.1rem;
        }

        .button {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 30px;
            font-size: 1rem;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin: 10px;
        }

        .button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }

        .button:active {
            transform: translateY(0);
        }

        .response {
            margin-top: 1.5rem;
            padding: 1rem;
            background: #f8f9fa;
            border-radius: 10px;
            min-height: 50px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: 'Courier New', monospace;
            color: #495057;
        }

        .loading {
            color: #667eea;
            font-style: italic;
        }

        .footer {
            margin-top: 2rem;
            color: #999;
            font-size: 0.9rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Hello from A_A!</h1>
        <p class="subtitle">极简全栈示例项目</p>
        
        <button class="button" onclick="testAPI()">测试后端连接</button>
        <button class="button" onclick="checkHealth()">健康检查</button>
        
        <div class="response" id="response">
            点击按钮测试后端连接
        </div>
        
        <div class="footer">
            前端：原生 HTML5 + JavaScript<br>
            后端：Node.js + Express
        </div>
    </div>

    <script>
        const responseDiv = document.getElementById('response');

        async function testAPI() {
            responseDiv.innerHTML = '<span class="loading">连接中...</span>';
            
            try {
                const response = await fetch('/api/ping');
                const data = await response.json();
                
                if (response.ok) {
                    responseDiv.innerHTML = `✅ 成功: ${JSON.stringify(data)}`;
                } else {
                    responseDiv.innerHTML = `❌ 错误: ${response.status}`;
                }
            } catch (error) {
                responseDiv.innerHTML = `❌ 连接失败: ${error.message}`;
            }
        }

        async function checkHealth() {
            responseDiv.innerHTML = '<span class="loading">检查中...</span>';
            
            try {
                const response = await fetch('/api/health');
                const data = await response.json();
                
                if (response.ok) {
                    responseDiv.innerHTML = `✅ 服务正常: ${JSON.stringify(data, null, 2)}`;
                } else {
                    responseDiv.innerHTML = `❌ 服务异常: ${response.status}`;
                }
            } catch (error) {
                responseDiv.innerHTML = `❌ 连接失败: ${error.message}`;
            }
        }

        // 页面加载时检查连接
        window.addEventListener('load', () => {
            setTimeout(() => {
                testAPI();
            }, 1000);
        });
    </script>
</body>
</html>
